// pages/carstore/storedetails.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentTab:0,
        serviceindex: 0,
        totalnum: 0,
        totalmoney: 0,
        activity: ["满100减10元", "满200减30元", "满500减100元"],
        store: {
            img: "/images/store1.png",
            name: "优车生活",
            sellnum: "43",
            address: "福建省厦门市富春街道-鹿山下126号 ",
            hprate: "99.7",
            servicestar: 4,
            abilitystar: 3,
			worktime:"9:00-22:00",
			discount:"折扣商品4.48折起(在线支付共享)",
			imglist: ["/images/smart3.jpg", "/images/smart3.jpg", "/images/smart3.jpg", "/images/smart3.jpg"],
			intro:"菲乐思飞集团由顶级国际俱乐部投资人以及经营专家Jonathan Ma于2007年创立，专注于开发健康与健身行业最顶级的产品。目前在北京拥有两家直营健身会所Le Wellness乐健身和一家高端瑜伽馆Le Yoga乐瑜伽。"

        },
        tab: ["服务", "评价", "商家"],
        service: [{
                typename: "推荐服务",
                ishot: "true",
                isrec: "false",
                term: [{
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    },
                    {
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    },
                    {
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    },
                    {
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    },
                    {
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    }
                ]
            },
            {
                typename: "汽车美容",
                ishot: "true",
                isrec: "false",
                term: [{
                        name: "全车ass镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    },
                    {
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    },
                    {
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    },
                    {
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    }
                ],
            },
            {
                typename: "轮胎服务",
                ishot: "true",
                isrec: "false",
                term: [{
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    },
                    {
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    },
                    {
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    },
                    {
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    }
                ]
            },
            {
                typename: "保养服务",
                ishot: "true",
                isrec: "false",
                term: [{
                        name: "全sd膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    },
                    {
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    },
                    {
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    },
                    {
                        name: "全车镀膜-KING WAX",
                        intro: "精洗+去污+抛光+镀膜",
                        price: "29.00",
                        num: 0
                    }
                ]
            }
        ],
        commentlist: [{
            touxiang: "/images/index5-1.png",
            username: "李先森",
            starnum: 4,
            content: "很好用，我很喜欢。奢润光采美肌 全新香奈儿奢华萃底妆全，新香奈儿奢华精萃底妆儿奢华精萃",
            imglist: ["/images/smart2.jpg", "/images/smart2.jpg", "/images/smart2.jpg"],
            visitnum: "233",
			iszan:false,
            zannum: 50
        }, {
            touxiang: "/images/index5-1.png",
            username: "李先森",
            starnum: 4,
            content: "很好用，我很喜欢。奢润光采美肌 全新香奈儿奢华萃底妆全，新香奈儿奢华精萃底妆儿奢华精萃",
            imglist: ["/images/smart2.jpg", "/images/smart2.jpg", "/images/smart2.jpg"],
            visitnum: "233",
				iszan: false,
            zannum: 50
        }, {
            touxiang: "/images/index5-1.png",
            username: "李先森",
            starnum: 4,
            content: "很好用，我很喜欢。奢润光采美肌 全新香奈儿奢华萃底妆全，新香奈儿奢华精萃底妆儿奢华精萃",
            imglist: ["/images/smart2.jpg", "/images/smart2.jpg", "/images/smart2.jpg"],
            visitnum: "233",
				iszan: false,
            zannum: 50
        }, ]
    },

    /**
     * 生命周期函数--监听页面加载
     */
	scrolla:function(e){
      console.log(e)
	},
    godetails: function() {
        wx.navigateTo({
            url: 'prodetails'
        })
    },
    servicetab: function(e) {
        this.setData({
            serviceindex: e.currentTarget.dataset.index
        })
    },
    swiperTab: function(e) {
        var that = this;
        that.setData({
            currentTab: e.detail.current
        });
    },
    //添加商品
    addnum: function(e) {
        var info = this.data.service;
        info[this.data.serviceindex].term[e.currentTarget.dataset.index].num++;
        this.setData({
            service: info
        })
        this.gettotal()
    },
    //删除商品
    cutnum: function(e) {
        var info = this.data.service;
        if (info[this.data.serviceindex].term[e.currentTarget.dataset.index].num != 0) {
            info[this.data.serviceindex].term[e.currentTarget.dataset.index].num--;
            this.setData({
                service: info
            })
        }
        this.gettotal()
    },

    //计算总数
    gettotal() {
        var temp = this.data.service;
        var price = 0;
        var num = 0;
        for (let i = 0; i < temp.length; i++) {
            for (let j = 0; j < temp[i].term.length; j++) {
                price += temp[i].term[j].num * temp[i].term[j].price
                num += temp[i].term[j].num
            }
        }
        this.setData({
            service: temp,
            totalnum: num,
            totalmoney: price
        })
    },
    //点击切换
    clickTab: function(e) {
        var that = this;
        if (this.data.currentTab === e.target.dataset.current) {
            return false;
        } else {
            that.setData({
                currentTab: e.target.dataset.current
            })
        }
    },
	dianzan:function(e){
		var temp=this.data.commentlist
		var index=e.currentTarget.dataset.index
		if(!temp[index].iszan){
			temp[index].zannum=temp[index].zannum+1
			temp[index].iszan=true
		 }else{
			temp[index].zannum=temp[index].zannum-1
			temp[index].iszan = false
		 }
		this.setData({
			commentlist:temp
		})

	},
    onLoad: function(options) {
        var that = this;
        wx.getSystemInfo({
            success: function(res) {
                that.setData({
                    height: res.windowHeight-213
                });
            }
        });

    },
	activity:function(){
  this.setData({
	  currentTab: 2
  })
	},

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})